package com.retrofit.demo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.retrofit.demo.entity.AssetEntity;
import com.retrofit.demo.entity.ProEntity;
import com.retrofit.library.JsonUtils;
import com.retrofit.library.RetrofitUtils;
import com.retrofit.library.callback.EntityListReqCallback;
import com.retrofit.library.callback.EntityReqCallback;
import com.retrofit.library.callback.JoReqCallback;
import com.retrofit.library.callback.RespCallback;
import com.retrofit.library.callback.StrReqCallback;
import com.retrofit.library.entity.Entity;
import com.retrofit.library.entity.ListEntity;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;
import retrofit2.Retrofit;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //        HttpUtil.request(HttpUtil.JS_URL);
        //        HttpUtil.request(HttpUtil.YD_URL);

       /* testLibraryStr();
        testLibraryEntity();
        testLibraryListEntity();*/

        testLibraryJson();
    }


    /**
     * 首页转让产品列表
     */
    String URL_TRANSFER_LIST = "order/order/transfer/homeList";
    /***
     * 我的总资产
     */
    String MY_QJSAssets = "order/order/myQJSAssets";

    String loginToken = "e26f954a820a4c5883c0fbe0a23cec96";

    private void testLibraryStr() {
        Map<String, Object> map = new HashMap<>();
        map.put("loginToken", loginToken);
        RetrofitUtils.getInstance().post(MY_QJSAssets, map, new StrReqCallback());
        //        {"code":"0000",
        // "message":"请求成功",
        // "data":{
        //        "qjsTotalAssetsAmount":"100.00",
        //        "qjsTotalYstProfit":"0.00",
        //        "qjsTotalAccumulatedProfit":"0.00",
        //        "qjsAccountBalanceAmount":"100.00",
        //        "currentAccountAmount":null,
        //        "reinvestAccountAmount":"0.00",
        //        "regularAccountAmount":"0.00",
        //        "isActiveEAccount":"0",
        //        "isDepositManage":"1",
        //         "availableCouponNum":"0"
        //       }
        // }
    }

    /**
     * 测试通过
     */
    private void testLibraryEntity() {
        Map<String, Object> map = new HashMap<>();
        map.put("loginToken", loginToken);

        Api api = RetrofitUtils.getRetrofit().create(Api.class);
        RequestBody body = RetrofitUtils.getInstance().postWithJson(map);
        api.queryAsset(RetrofitUtils.getInstance().getHeaderToken(), body)
           .enqueue(new EntityReqCallback<AssetEntity>() {

               @Override
               protected void parseData(AssetEntity assetEntity) {
                   Log.e("RetrofitDemo==>>", assetEntity.toString());
               }
           });


    }

    /**
     * 测试通过
     */
    private void testLibraryJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("loginToken", loginToken);

        Api api = RetrofitUtils.getRetrofit().create(Api.class);
        RequestBody body = RetrofitUtils.getInstance().postWithJson(map);
        api.queryAssetJO(RetrofitUtils.getInstance().getHeaderToken(), body)
           .enqueue(new JoReqCallback() {
               @Override
               protected void parseData(JSONObject data) {
                   Log.e("JSONObject==>>", JsonUtils.toJson(data));
               }
           });


    }



    /**
     * 测试通过
     */
    private void testLibraryListEntity() {
        Map<String, Object> map = new HashMap<>();
        map.put("loginToken", loginToken);

        Api api = RetrofitUtils.getRetrofit().create(Api.class);
        RequestBody body = RetrofitUtils.getInstance().postWithJson(map);
        api.queryNewProList(RetrofitUtils.getInstance().getHeaderToken(), body)
           .enqueue(new EntityListReqCallback<ProEntity>() {

               @Override
               protected void parseData(List<ProEntity> data) {
                   for (ProEntity pro : data) {
                       Log.e("RetrofitDemo==>>", pro.toString() + "\n");
                   }
               }
           });


    }


}
